package kgame5.k25d.core {
	import kgame5.k3d.core.math.Vector3D;

	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.geom.Rectangle;

	/**
	 * @author max
	 * 2010-12-14
	 * 25D世界里的摄像机
	 */
	public class Camera25D {
		
		
		public var viewRect:Rectangle;//由外部直接操作
		
		public var target:Vector3D;//3D世界中的目标，注意不是投影之后的,注意，y不考虑
		private var mc_world:DisplayObject;//由外部传入，裁剪用
		
		
		public function Camera25D(mc_world:DisplayObject){
			viewRect=new Rectangle(0,0,400,400);
			target=new Vector3D();
			this.mc_world=mc_world;
			
			
		}
		
	
		
		//是否可以裁剪掉了
		public function canCull(mc:DisplayObject):Boolean{
			return mc.getBounds(mc_world).intersection(viewRect)==null;
		}
		
		public var dragging:Boolean=false;
		
		//更新了target,更新viewRect,注意这个要在world之前执行
		public function update():void{
			
			//没有拖拽的时候才使用摄像机定点呢
			if(dragging==false){
				var x:int=target.x;
				//var y:int=v3d_target.y;
				var z:int=target.z;
				
				var screenX:Number =x- z;
				var screenY:Number = (x+ z)*0.5;
				
				viewRect.x=screenX-viewRect.width*0.5;
				viewRect.y=screenY-viewRect.height*0.5;
			}
			
			mc_world.scrollRect=viewRect;
		}
	}
}
